package com.common.util;

import java.util.Collection;
import java.util.Map;

import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import com.common.api.exception.CommonException;

public class AssertUtil {

	public static void isTrue(boolean expression, String message) {
		if (!expression) {
			throw new CommonException(message);
		}
	}
	
	public static void isFalse(boolean expression, String message) {
		if (expression) {
			throw new CommonException(message);
		}
	}
	
	public static void isNull(@Nullable Object object, String message) {
		if (object != null) {
			throw new CommonException(message);
		}
	}
	
	public static void notNull(@Nullable Object object, String message) {
		if (object == null) {
			throw new CommonException(message);
		}
	}
	
	public static void hasLength(@Nullable String text, String message) {
		if (!StringUtils.hasLength(text)) {
			throw new CommonException(message);
		}
	}
	
	public static void notEmpty(@Nullable Collection<?> collection, String message) {
		if (CollectionUtils.isEmpty(collection)) {
			throw new CommonException(message);
		}
	}
	
	public static void notEmpty(@Nullable Map<?, ?> map, String message) {
		if (CollectionUtils.isEmpty(map)) {
			throw new CommonException(message);
		}
	}
}
